package ui;

import java.io.IOException;

import mainBoerse.AccountManagerImpl;
import interfaces.AccountManager;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

public class StartAgentWindow extends Application{
	
	private AccountManager acc;
	private Stage stage;
	
	public StartAgentWindow() throws IOException {
		this.acc = AccountManagerImpl.getInstance();
		
	}
	
	@Override
	public void start(Stage primaryStage) throws Exception {
		stage = primaryStage;
		primaryStage.setTitle("Start Player Agent");
		GridPane grid = new GridPane();
		TextField playerNameField = new TextField();
		Label playerNameFieldLabel = new Label("Playername: ");
		grid.add(playerNameFieldLabel, 0, 1);
		grid.add(playerNameField,1,1);
		
		Button crp = new Button("Start Agent");
		crp.setOnAction(new EventHandler<ActionEvent>() {
			
			@Override
			public void handle(ActionEvent event) {
				Platform.runLater(new Runnable(){
				      @Override 
				      public void run() {
				         try {
							acc.playerAgent(playerNameField.getText().toUpperCase());
						} catch (Exception e) {
							// TODO Auto-generated catch block
							CommandReaderUI.setErrLabel(e.getMessage());
						}
				      };
				   });
				
				stage.close();
			}
		});
		grid.add(crp, 0, 2);
		
		Scene scene = new Scene(new VBox(),250,80);
		((VBox) scene.getRoot()).getChildren().add(grid);
		primaryStage.setScene(scene);
		primaryStage.show();
		
	}

}
